package com.example.a22310.myapplication.ViewModel.Activity;


import android.content.SharedPreferences;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Toast;

import com.example.a22310.myapplication.Beans.user;
import com.example.a22310.myapplication.Listener.ActivityLisenter;
import com.example.a22310.myapplication.Model.ActivityModel;

public class ActivityApplyViewModel implements ActivityLisenter<user> {
    private ActivityApplyBinding binding;
    private AppCompatActivity activity;
    private int userid,activityid;

    private SharedPreferences sharedPreferences;
    private SharedPreferences.Editor editor;

    private int number ;

    public ActivityApplyViewModel(AppCompatActivity activity, ActivityApplyBinding binding,int userid,int
            activityid,int number){
        this.activity = activity;
        this.binding = binding;
        this.userid = userid;
        this.activityid = activityid;
        this.number = number;
        binding.setModel(this);
    }

    public void back(View view){
        activity.onBackPressed();
        activity.finish();
    }
    public void apply(View view){
        ActivityModel activityModel=new ActivityModel();
        activityModel.activityAplay(ActivityApplyViewModel.this,userid,activityid,binding.name.getText().toString(),
                binding.type.getText().toString(),binding.price.getText().toString(),binding.phone.getText().toString(),
                binding.userName.getText().toString(),number+"");
    }



    @Override
    public void onSuccess(user user) {
        if (user.getSuccess() ==1){
            Toast.makeText(activity,"下单成功",Toast.LENGTH_LONG).show();
            activity.onBackPressed();
        }
    }





    @Override
    public void onFailure() {
        Toast.makeText(activity,"连接服务器失败", Toast.LENGTH_LONG).show();
    }




    public  void subtraction(View view){

    }

    private class ActivityApplyBinding {
    }
}


